//
//  Poze.m
//  iDent
//
//  Created by Marius Corega on 6/28/09.
//  Copyright 2009 Marius Corega. All rights reserved.
//

#import "Poze.h"


@implementation Poze



- (id)initWithXMLData: (NSData*) data
{
	self = [super initWithXMLData:data tableName:@"poze" elementName:@"poza"];
	
	
	return self;
}

-(id) initWithServerURL:(NSURL*) url
{
	NSMutableDictionary* d = [NSMutableDictionary dictionary];
	[d setObject:@"poze" forKey:@"tabel"];
	_grupSelectat = @"toate";
	_pozeSelectate = nil;
	self = [self initWithServerURL:url postDict:d];
	return self;
}

-(BOOL) containsString:(NSString*)object inArray:(NSArray*) array
{
	for(NSInteger i=0; i<[array count]; i++)
		if([[array objectAtIndex:i] isEqualToString:object]) 
		{
			return YES;
			break;
		}
	return NO;
}

-(NSMutableArray*)grupPoze
{
	static NSMutableArray* res = nil;
	
	if(!res) res = [[NSMutableArray alloc] init];
	[res removeAllObjects];
	
	for(NSInteger i=0; i<[_elemente count]; i++)
	{
		if(![self containsString:[[_elemente objectAtIndex:i] objectForKey:@"data"] inArray:res])
		{
			[res addObject:[[_elemente objectAtIndex:i]objectForKey:@"data"]];
		}
	}
	[res addObject:@"toate"];
	return res;
}

-(NSString*) grupSelectat
{
	return _grupSelectat;
}

-(void)setGrupSelectat:(NSString*) grup;
{
	if(_grupSelectat) {[_grupSelectat release]; _grupSelectat = nil;}
	_grupSelectat = grup;
	[_grupSelectat retain];
	
	if(_pozeSelectate) {[_pozeSelectate release]; _pozeSelectate = nil;}
	_pozeSelectate = [[NSMutableArray alloc] init];
	
	if([_grupSelectat isEqualToString:@"toate"]) {_pozeSelectate = _elemente; [_pozeSelectate retain];}
	else
		for(NSUInteger i=0; i<[_elemente count]; i++)
			if([[[_elemente objectAtIndex:i] objectForKey:@"data"] isEqualToString:_grupSelectat]) [_pozeSelectate addObject:[_elemente objectAtIndex:i]];

	
}

- (NSMutableArray*)poze
{
	if(_grupSelectat)	
	if([_grupSelectat isEqualToString:@"toate"]) return _elemente;
		
	return _pozeSelectate;
	
	//return _elemente;
}

-(void)dealloc
{

	[super dealloc];
}


@end
